﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web.Routing;
using Microsoft.Practices.Unity;
using Vit.Common;

namespace Vit.Web.Mvc
{
    public class UnityControllerActivator : IControllerActivator
    {
        public UnityControllerActivator()
        {
        }

        #region IControllerActivator Members

        public IController Create(RequestContext requestContext, Type controllerType)
        {
            IController controller = Unity.Current.Resolve(controllerType) as IController;
            if (controller == null)
            {
                controller = Activator.CreateInstance(controllerType) as IController;
                Unity.Current.RegisterInstance(controllerType, controller);
            }

            return controller;
        }

        #endregion
    }
}
